package main

import (
	"fmt"
)

func main() {
	fmt.Println("切片 - slice")
	//声明整型切片
	var numList []int
	fmt.Println("整型切片:", numList)

	// 声明一个空切片
	var numListEmpty = []int{}
	fmt.Println("空切片:", numListEmpty)

	fmt.Println()
	numList1 := make([]int, 3, 5)
	fmt.Println("numList1 = ", numList1)

	fmt.Println()
	arr := [5]string{"Go", "PHP", "JAVA", "Python", "C++"}
	var s1 = arr[1:4]
	fmt.Println("arr = ", arr)
	fmt.Println("s1 = ", s1)

	fmt.Println()
	//s := make([]string, 3, 5)
	//fmt.Println("s = ", s)

	//s := make([]int, 3, 5)
	//fmt.Println(s[10])

	modifySlice()
	fmt.Println()
	appendSliceData()

	fmt.Println()
	scores := make(map[int]int)
	fmt.Println(scores)
	steps := make(map[string]string)
	fmt.Println(steps)

	fmt.Println()
	var steps2 map[string]string = map[string]string{
		"第一步": "Go语言",
		"第二步": "Go语言熟练",
		"第三步": "微服务架构师",
	}
	fmt.Println(steps2)

	fmt.Println()
	mapByReference()
}

func mapByReference() {
	steps4 := map[string]string{
		"第一步": "Go语言",
		"第二步": "Go语言熟练",
		"第三步": "微服务架构师",
	}
	fmt.Println("steps4 = ", steps4)
	newSteps4 := steps4
	newSteps4["第1步"] = "Go语言"
	newSteps4["第2步"] = "动手练习"
	newSteps4["第3步"] = "增加练习"
	fmt.Println("steps4: ", steps4)
	fmt.Println("newSteps4: ", newSteps4)
}

func appendSliceData() {
	s := []string{"Go语言入门"}
	fmt.Println(s)
	fmt.Println(cap(s))

	s = append(s, "Go语言微服务架构核心")
	fmt.Println(s)
	fmt.Println(cap(s))

	s = append(s, "从0到Go语言微服务架构师", "分布式")
	fmt.Println(s)
	fmt.Println(cap(s))

	s = append(s, []string{"微服务", "分布式锁"}...)
	fmt.Println(s)
	fmt.Println(cap(s))
}

func modifySlice() {
	var arr = [...]string{"Go", "PHP", "JAVA", "Python", "C++"}
	s := arr[:]
	fmt.Println(arr)
	fmt.Println(s)

	s[0] = "Go语言"
	fmt.Println(arr)
	fmt.Println(s)
}
